home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / samples / zscript / fastuniq.zsc.z / fastuniq.zsc
Encoding:
Text File  |  1997-01-22  |  2.3 KB  |  84 lines

  1. # Sample Z-Script  functions: fastuniq, do_uniq
  2. #               button: Uniq
  3.  
  4. # This file is provided for comparison to uniq.zsc.  It performs the same
  5. # operation, but is significantly faster because it examines only adjacent
  6. # messages.  "uniq" preserves sorting order of the folder; this sacrifices
  7. # sorting order for speed of operation.
  8.  
  9. function fastuniq() {
  10. #%
  11. # Cull duplicate messages out of a folder.  Useful if you've saved the
  12. # same message more than once or merged together two folders that had
  13. # some overlap.  Deletes the argument message (e.g., the selected message,
  14. # if attached to a button in GUI mode) if the next message after it has
  15. # the same Message-ID: header.  Ignores messages that are already deleted.
  16. #
  17. # NOTE that this requires that the messages be sorted so that duplicates
  18. # are adjacent!  It's possible to scan the entire folder for duplicates,
  19. # but much more time-consuming.  See "uniq".
  20. #
  21. # To apply this function to all the messages, just do:
  22. #
  23. #    sort -d -r -S
  24. #    each * fastuniq
  25. #
  26. # This function requires Z-Mail 3.0 and later (for the "arith" command).
  27. #%
  28. #
  29.     unset any same first next    # Initialize variable state
  30.     set deleted=""
  31.     if $?1
  32.     msg_list - $1    # Set current message = first argument
  33.     else
  34.     msg_list - 1    # Set current message = first message
  35.     endif
  36.     if $status != 0
  37.     return
  38.     endif
  39.     msg_list . { $ } | set next
  40.     if ! $?next
  41.     return 0
  42.     endif
  43.     arith next += 1
  44.     #
  45.     # Get the deleted messages -- speeds up later operations.
  46.     #
  47.     msg_list . - $next | :d | set deleted
  48.     #
  49.     # If the current message is deleted, don't do anything
  50.     #
  51.     msg_list . { $deleted } | set any
  52.     if $?any == 0
  53.     return 0
  54.     endif
  55.     #
  56.     # See if the next message has the same message ID as this one
  57.     #
  58.     eval -h pick -r $next { $deleted } -h message-id %i | set same
  59.     #
  60.     # Sanity check -- perhaps the header is missing?
  61.     #
  62.     if $?same
  63.     msg_list . | set first
  64.     echo Deleting $first
  65.     delete $first
  66.     msg_list $same        # The "output" of fastuniq is $same
  67. #    else
  68. #    echo -p No duplicates of %m found
  69.     endif
  70.     return 0
  71. }
  72.  
  73. function do_uniq() {
  74.     set reply_to_hdr = message-id
  75.     echo Sorting by message-id ...
  76.     sort -a -S -d    # -d -r -S is faster but less accurate
  77.     unset reply_to_hdr
  78.     echo Scanning ...
  79.     each * fastuniq
  80.     sort -d -S        # restore date-sent ordering
  81.     echo Done.
  82. }
  83. button -n Uniq do_uniq
  84.